/*****************************************************************************
 * gtk_extra.c : GTK+ plugin for vlc
 *****************************************************************************/

#include <stdlib.h>
#include <string.h>

#include <gtk/gtk.h>

#include "gtk_extra.h"

void
gtk_init_without_args (void)
{

  /* We fake an empty command line */
  char *args[] = {(char*)"", NULL};
  char **argv  = args;
  int argc = 1;

  gtk_init (&argc, &argv);

}

void
gtk_file_filter_add_multiple_pattern (GtkFileFilter *filter, const gchar *pattern_list)
{

  gchar **str_array;
  int i;

  str_array = g_strsplit (pattern_list, ";", -1);

  for (i = 0; str_array[i] != NULL; i++)
    {
      gtk_file_filter_add_pattern (filter, str_array[i]);
    }

  g_strfreev (str_array);

}

GtkWidget*
gtk_image_menu_item_new_with_qt_mnemonic_style (GtkWidget* image, const gchar* label)
{

  GtkWidget *widget;
  gchar *label_buffer;
  guint i;

  label_buffer = g_strdup (label);

  for (i = 0; i < strlen (label_buffer); i++)
    {
      if ( label_buffer[i] == '&')
        {
          label_buffer[i] = '_';
        }
    }

  widget = gtk_image_menu_item_new_with_mnemonic (label_buffer);
  gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(widget), image);
  g_free (label_buffer);

  return widget;

}

GtkWidget*
gtk_menu_item_new_with_qt_mnemonic_style (const gchar *label)
{

  GtkWidget *widget;
  gchar *label_buffer;

  label_buffer = qt_to_gtk_mnemonic_string (label);

  widget = gtk_menu_item_new_with_mnemonic (label_buffer);
  g_free (label_buffer);

  return widget;

}

GtkWidget*
gtk_label_new_with_qt_mnemonic_style (const gchar *label)
{

  GtkWidget *widget;
  gchar *label_buffer;

  label_buffer = qt_to_gtk_mnemonic_string (label);

  widget = gtk_label_new_with_mnemonic (label_buffer);
  g_free (label_buffer);

  return widget;

}

GtkWidget*
gtk_image_new_from_vlc_stock (const guint8 *data, guint size)
{

  GtkWidget *widget;
  GdkPixbuf *pixbuf;
  GdkPixbuf *scale;
  
  pixbuf = gdk_pixbuf_new_from_inline (-1, data, FALSE, NULL);  

  scale = gdk_pixbuf_scale_simple (pixbuf, size, size, GDK_INTERP_BILINEAR);

  widget = gtk_image_new_from_pixbuf (scale);

  g_object_unref (scale);
  g_object_unref (pixbuf);  

  return widget;

}

gchar*
qt_to_gtk_mnemonic_string (const gchar* label)
{

  gchar *label_buffer;
  guint i;

  label_buffer = g_strdup (label);

  for (i = 0; i < strlen (label_buffer); i++)
    {
      if ( label_buffer[i] == '&')
        {
          label_buffer[i] = '_';
        }
    }
    
  return label_buffer;

}

